package com.android.zmusic.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.zmusic.musicplay.MenuItemData;
import com.android.zmusic.ui.R;

public class GridViewAdapter extends BaseAdapter {
	
	private Context context ;
	private LayoutInflater inflater;
	private MenuItemData mMenuItemData ;

	public GridViewAdapter(Context context,
			MenuItemData mMenuItemData) {
		
		this.context = context;
		this.mMenuItemData = mMenuItemData;
		inflater = LayoutInflater.from(context);
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mMenuItemData.getCount();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(convertView == null) {
			convertView = inflater.inflate(R.layout.menu_item, null);
		}
		
		ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
		TextView textView = (TextView) convertView.findViewById(R.id.textView);
		imageView.setImageDrawable(mMenuItemData.getDrawable(position));
		textView.setText(mMenuItemData.getTitle(position));
		return convertView;
	}

}
